import request from '../utils/request'

export const getCfyList = ()=>{
    return request.get('/1.1/classes/Cfy')
}

export const todoAdd = (task)=>{  //新增任务
    return request.post('/1.1/classes/Todo',task)
}

export const todoGet = ()=>{  //加载任务列表
    return request.get('/1.1/classes/Todo')
}

export const todoUpdate = (objectId,newData)=>{  //更新任务信息
    return request.put(`/1.1/classes/Todo/${objectId}`,newData)
}

export const todoDel = (objectId)=>{  //删除单个任务
    return request.delete(`/1.1/classes/Todo/${objectId}`)
}

export const todoBatch = (todolist,method="DELETE",bool)=>{ //批量操作接口
    // bool  新的全选状态
    // {
    //     "requests": [
    //       {
    //         "method": "DELETE",
    //         "path": "/1.1/classes/Post/55a39634e4b0ed48f0c1845c"
    //       }
    //     ]
    // }
    let data = {
        "requests":[]
    }
    todolist.forEach(item=>{
        let obj = {
            method,
            "path": `/1.1/classes/Todo/${item.objectId}`
        }
        if(item.ischeck&&method=='DELETE'){ //批量删除
            data.requests.push(obj)
        }
        if(method=='PUT'){ //批量更新
            obj.body = {ischeck:bool}
            data.requests.push(obj)
        }
    })
    return request.post('/1.1/batch',data)
}